// var i;
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_GameClubButton = require("./AL_GAME_HUA_GameClubButton");
// var l = cc._decorator;
// var u = l.ccclass;
// var p =
//     (l.property,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.record = [];
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.start = function () {
//             var t = this;
//             e.prototype.start.call(this);
//             AL_APP_SDK_MANAGER.on(
//                 AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE,
//                 function (e) {
//                     if (e.node) {
//                         e.hide
//                             ? (-1 == t.record.indexOf(e.node) && t.record.push(e.node), t.hide())
//                             : (t.record.remove(e.node), 0 == t.record.length && t.show());
//                     }
//                 },
//                 this
//             );
//         };
//         t.prototype.show = function () {
//             e.prototype.show.call(this);
//         };
//         t.prototype.hide = function () {
//             e.prototype.hide.call(this);
//         };
//         t.prototype.onDestroy = function () {
//             AL_APP_SDK_MANAGER.off(this);
//             if (e.prototype.onDestroy) {
//                 e.prototype.onDestroy.call(this);
//             }
//         };
//         return __decorate([u], t);
//     })(AL_GAME_HUA_GameClubButton.default));
// exports.default = p;

const lY01_HDPP_Define = require("./AL_GAME_HUA_Define");
const lY01_HDPP_GameClubButton = require("./AL_GAME_HUA_GameClubButton");
const { ccclass, property } = cc._decorator;

/**
 * This class represents a game club button that manages visibility state based on events.
 */
@ccclass
class GameClubButtonManager extends lY01_HDPP_GameClubButton.default {
    constructor() {
        super();
        /** @type {Array} Used to keep track of nodes to show/hide. */
        this.record = [];
    }

    /**
     * Lifecycle method called when the component is first enabled.
     */
    start() {
        super.start();

        // Bind event listener to handle game club hide/show events.
        AL_APP_SDK_MANAGER.on(lY01_HDPP_Define.GameEvent.ON_GAME_CLUB_HIDE, (event) => {
            if (event.node) {
                if (event.hide) {
                    if (!this.record.includes(event.node)) {
                        this.record.push(event.node);
                    }
                    this.hide();
                } else {
                    this.record = this.record.filter(node => node !== event.node);
                    if (this.record.length === 0) {
                        this.show();
                    }
                }
            }
        }, this);
    }

    /**
     * Shows the game club button.
     */
    show() {
        super.show();
    }

    /**
     * Hides the game club button.
     */
    hide() {
        super.hide();
    }

    /**
     * Method called before the component is destroyed.
     */
    onDestroy() {
        // Remove event listeners related to this component.
        AL_APP_SDK_MANAGER.off(this);
        if (super.onDestroy) {
            super.onDestroy();
        }
    }
}

exports.default = GameClubButtonManager;